package com.goldcn.user.service;

import com.goldcn.common.util.IdGen;
import com.goldcn.interceptor.SystemContext;
import com.goldcn.user.dao.PermissionsMapper;
import com.goldcn.user.dto.StateDto;
import com.goldcn.user.model.Permissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by 1111 on 2016/11/8.
 */
@Service
@Transactional
public class PermissionsService {
    @Autowired
    PermissionsMapper permissionsMapper;

    public Long addPermissions(Permissions permissions){
        permissions.setPsID(IdGen.get().nextId());
        permissions.setIsStop(0); //默认不停用
        permissions.setCompanyID(SystemContext.getCompanyID());
        permissionsMapper.insert(permissions);
        return permissions.getPsID();
    }

    public String updatePermissions(Permissions permissions){
        permissionsMapper.updateByPrimaryKey(permissions);
        return "success";
    }

    public String deletePermissions(Long psID){
        permissionsMapper.deleteByPrimaryKey(psID);
        return "success";
    }

    public Permissions selectPermissions(Long psID){
        return permissionsMapper.selectByPrimaryKey(psID);
    }

    public String updateIsStop(StateDto stateDto){
        permissionsMapper.updateIsStop(stateDto);
        return "success";
    }

    public List<Permissions> selectByPermissions(Permissions record){
        record.setCompanyID(SystemContext.getCompanyID());
        return permissionsMapper.selectByPermissions(record);
    }
}
